<#import "/common.ftl" as common />
<@common.commomFrame >
	<div id="breadcrumb">
		<ul class="breadcrumb">
			 <li><i class="fa fa-home"></i><a href="index-2.html">首页</a></li>
			 <li class="active">黑板报</li>
		</ul>
	</div>
	
	<div class="padding-md" >
		<div class="panel panel-default table-responsive">
			<div class="panel-body">
				<a href="/train/add" class="btn btn-info btn-xs" ><i class="fa fa-plus fa-lg"></i> 新增</a>
				
				<a href="#addForm" class="btn btn-info btn-xs" data-toggle="modal" style="float:right"><i class="fa fa-plus fa-lg"></i> 上传新车次时刻信息</a>
				<a class="btn btn-danger btn-xs" onclick="deleteData()" style="float:right;margin-right:16px"><i class="fa fa-wrench fa-lg"></i> 删除旧数据</a>
				
			</div>
			<div class="panel-heading">条件搜索</div>
			<div class="panel-body">
				<form id="searchForm" class="form-inline no-margin" action="/train/manageList" method="post">
					<div class="form-group" style="margin-right:10px;">
						<label class="control-label">车次</label>
						<div>
							<input name="trainName" type="text" class="form-control input-sm" value="${(train.trainName)!}"/>
						</div>
					</div>
					<div class="form-group" style="margin-right:10px;">
						<label class="control-label">到达时间</label>
						<div>
							<input name="reachTimeStr" type="text" class="form-control input-sm" value="${(train.reachTime)!}"/>
						</div>
					</div>
					<div class="form-group" style="margin-right:10px;">
						<label class="control-label">发车时间</label>
						<div>
							<input name="leaveTimeStr" type="text" class="form-control input-sm" value="${(train.leaveTime)!}"/>
						</div>
					</div>
					<div class="form-group" style="margin-right:10px;">
						<label class="control-label">是否上水</label>
						<div>
							<select class="form-control chzn-select" name="isAddWater" >
								<option value="">全部</option>
								<option value="1" <#if (train.isAddWater)?? && train.isAddWater == 1>selected</#if>>是</option>
								<option value="0" <#if (train.isAddWater)?? && train.isAddWater == 0>selected</#if>>否</option>
							</select>
						</div>
					</div>
					<div class="form-group" style="margin-right:10px;">
						<label class="control-label">是否去污</label>
						<div>
							<select class="form-control chzn-select" name="isDealRubbish" >
								<option value="">全部</option>
								<option value="1"  <#if (train.isDealRubbish)?? && train.isDealRubbish == 1>selected</#if>>是</option>
								<option value="0"  <#if (train.isDealRubbish)?? && train.isDealRubbish == 0>selected</#if>>否</option>
							</select>
						</div>
					</div>
					<button type="submit" class="btn btn-sm btn-success"><i class="fa fa-search" style="font-size:16px;"></i></button>
				</form>
			</div>
			<table class="table table-bordered table-condensed table-hover table-striped" id="responsiveTable">
				<thead>
					<tr>
						<th>车次名称</th>
						<th>始发站</th>
						<th>终点站</th>
						<th>到达时间</th>
						<th>发车时间</th>
						<th>接车股道</th>
						<th>发车股道</th>
						<th>接车序列</th>
						<th>发车序列</th>
						<th>是否上水</th>
						<th>是否去污</th>
						<th>状态</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<#if trainList?? && trainList?size gt 0>
						<#list trainList as train>
						<tr>
							<td>${(train.trainName)!}</td>
							<td>${(train.startStationName)!}</td>
							<td>${(train.endStationName)!}</td>
							<td>
								<#if (train.reachTime)??>${train.reachTime?string('HH:mm:ss')}</#if>
							</td>
							<td>
								<#if (train.leaveTime)??>${train.leaveTime?string('HH:mm:ss')}</#if>
							</td>
							<td>${(train.pickUpTrack)!}股</td>
							<td>${(train.departureTrack)!}股</td>
							<td>${(train.pickUpSequence)!}</td>
							<td>${(train.departureSequence)!}</td>
							<td>
								<#if (train.isAddWater)?? &&train.isAddWater ==1>
								<span class="label label-info">是</span>
								<#elseif (train.isAddWater)?? && train.isAddWater ==0>
									<span class="label label-default">否</span>
								</#if>
							</td>
							<td>
								<#if (train.isDealRubbish)?? &&train.isDealRubbish ==1>
								<span class="label label-info">是</span>
								<#elseif (train.isDealRubbish)?? && train.isDealRubbish ==0>
									<span class="label label-default">否</span>
								</#if>
							</td>
							<td>
								<#if (train.state)?? &&train.state ==1>
								<span class="label label-danger">未核对</span>
								<#elseif (train.state)?? && train.state ==2>
									<span class="label label-success">已核对</span>
								</#if>
							</td>
							<td>
								<a class="btn btn-xs btn-success" href="/train/edit?trainId=${(train.trainId)!}"><i class="fa fa-wrench fa-lg"></i> 编辑</a>
								
								<a class="btn btn-xs btn-warning" href="/train/info?trainId=${(train.trainId)!}"><i class="fa fa-wrench fa-lg"></i> 查看详情</a>
							</td>
						</tr>
						</#list>
					</#if>
				</tbody>
			</table>
			<div class="panel-footer clearfix">
				<span class="label label-info pull-left">当前第 ${(train.pageNo)!}页  共 ${(train.pageTotal)!} 页  共 ${(train.recordTotal)!} 条记录</span>
				<ul class="pagination pagination-xs m-top-none pull-right">
					<li><a href="javascript:GoPage(1);">首页</a></li>
					<li <#if train.pageNo?? && (train.pageNo - 1) lt 1>class="disabled" </#if> ><a href="javascript:GoPage(${(train.pageNo) - 1});">上一页</a></li>
					<li class="active"><a href="javascript:GoPage(${(train.pageNo)!});">${(train.pageNo)!}</a></li>
					<li <#if train.pageNo?? && (train.pageNo + 1) gt train.pageTotal>class="disabled" </#if>><a href="javascript:GoPage(${(train.pageNo) + 1});">下一页</a></li>
					<li><a href="javascript:GoPage(${(train.pageTotal)!});">尾页</a></li>
				</ul>
			</div>
		</div>
	</div>
	
	
	<#-- 上传文件form -->
	<div class="modal fade" id="addForm">
		<div class="modal-dialog">
			<div class="modal-content">
  				<div class="modal-header">
    				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4>请选择您要上传的文件</h4>
  				</div>
			    <div class="modal-body">
					<form id="fileUploadForm" class="form-horizontal form-border" method="post"  enctype="multipart/form-data">
						<div class="form-group">
							<label class="control-label col-md-2">文件：</label>
							<div class="col-md-8">
								<div class="upload-file">
									<input type="file" id="file" name="file" class="upload-demo">
									<label data-title="选择文件" for="file">
										<span data-title="未选择文件..."></span>
									</label>
								</div>
							</div>
						</div>
						<div class="form-group text-center">
							<button type="button" class="btn btn-success" onclick="uploadFile()"> 上传文件  </button>
							<button type="button" class="btn btn-default" data-dismiss="modal"> 关闭  </button>
						</div>
					</form>
			    </div>
		  	</div>
		</div>
	</div>
	<script language="javascript">
		GoPage = function(pageNo){
			$("input[name = pageNo]").remove();
			$("#searchForm").append("<input type='hidden' id='searchForm_pageNo' name='pageNo' value='" + pageNo + "' />");
			$("#searchForm").submit();
		};
		
		function deleteData (){
			alertify.confirm("确定删除吗？",function (e) {
				if(e){
					alertify.success("你点击了确定");
					$.ajax({
						cache: true,
						type: "POST",
						url:"/train/deleteAll",
						async: false,
						error: function(request) {
							alertify.alert("错误：服务器异常！");
						},
						success: function(data) {
							if(data.success){
								alertify.alert("删除成功！",function(){
									window.location.reload();
								});
							}else{
								alertify.alert("错误:" + data.message);
							}
						}
					});
			    }else{
					alertify.error("你点击了取消");
			    }
			});
		}
		
		
		function uploadFile(){
			var fileName = $('#file').val();
			if($.trim(fileName) != ""){
				var i = fileName.indexOf(".xls");
				if(i != -1){
					var formData = new FormData(document.getElementById("fileUploadForm"));  
					$.ajax({
						cache: true,
						type: "POST",
						url:"/train/fileUpload",
						data:formData,
						async: false,
						contentType: false,
						processData: false,
						error: function(request) {
							alertify.alert("错误：服务器异常！");
						},
						success: function(data) {
							if(data.success){
								alertify.alert("文件上传成功！",function(){
									window.location.reload();
								});
							}else{
								alertify.alert("错误:" + data.message);
							}
						}
					});
				}else{
					alertify.alert("请上传EXCLE文件");
					return;
				}
			}else{
				alertify.alert("请选择要上传的文件");
				return;
			}
		}
	</script>
</@common.commomFrame>